//
//  BoxDownLoadViewController.m
//  WuliHanhan
//
//  Created by tang on 16/3/9.
//  Copyright © 2016年 LVpeng. All rights reserved.
//

#import "BoxDownLoadViewController.h"
#import "Header.h"

#import "ImagePushButton.h"



#import "DownLoadImageCollectionViewCell.h"
//#import "CreatImageWithTextViewController.h"

@interface BoxDownLoadViewController ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,ImagePushButtonDelegate>
{
    ImagePushButton *imagePushButton;
}

@property (strong, nonatomic)UICollectionView *collectionView;


@end

@implementation BoxDownLoadViewController

- (void)loadView
{
    [super loadView];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    
    UIView *titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WithView, 44.0)];
    [titleView setBackgroundColor:uicolor(254, 195, 9)];
    [self.view addSubview:titleView];
    
    UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 12.5, WithView, 20.0)];
    [titleLable setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:titleLable];
    [titleLable setText:@"我的收藏"];
    [titleLable setTextColor:uicolor(13, 20, 25)];

    
    
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    
    self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, 320, heightView-64) collectionViewLayout:flowLayout];
    self.collectionView.dataSource=self;
    self.collectionView.delegate=self;
    [self.collectionView setBackgroundColor:[UIColor clearColor]];
    
    //注册Cell，必须要有
    [self.collectionView registerClass:[DownLoadImageCollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
    
    [self.view addSubview:self.collectionView];
    
    
    UIImage *image = nil;
    
    image = [UIImage imageNamed:@"quxiao.png"];
    
    UIButton *calcanButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    [calcanButton setBackgroundImage:image forState:UIControlStateNormal];
    [self.view addSubview:calcanButton];
    [calcanButton addTarget:self action:@selector(cancleToPopView) forControlEvents:UIControlEventTouchUpInside];
    
    imagePushButton = [[ImagePushButton alloc] initWithFrame:CGRectMake(0, 0, 64, 26)];
    [imagePushButton setCenter:CGPointMake(WithView-42.0, 22.0)];
    [imagePushButton setMImagePushButtonDelegate:self];
    [self.view addSubview:imagePushButton];

}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



//返回
- (void)cancleToPopView
{
    [self dismissViewControllerAnimated:YES completion:nil];
//    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}



//进入创作
- (void)pushToCreatView
{
//    if (_plusImage)
//    {
//        [self dismissViewControllerAnimated:YES completion:nil];
//        
//    }
//    else
//    {
//        CreatImageWithTextViewController *creatImageVC = [[CreatImageWithTextViewController alloc] init];
//        [self.navigationController pushViewController:creatImageVC animated:YES];
//    }

}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}


//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"UICollectionViewCell";
    DownLoadImageCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    //    NSLog(@"%@", [_imageArray objectAtIndex:indexPath.row]);
    //    NSLog(@"%@", _imageArray[indexPath.row]);
    return cell;
}

#pragma mark --UICollectionViewDelegateFlowLayout

//定义每个Item 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(biliwith(77.0), biliwith(77.0));
}

//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}



- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    return 4.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 4.0;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
